﻿using NLua;
using System;
using TaleWorlds.Library;

namespace OptimizationPlus.Extensions
{
    public static class LuaTableExtension
    {
        public static object[] InvokeFunc(this LuaTable table, string methodName, params object[] args)
        {
            try
            {
                if (table[methodName] is LuaFunction func)
                {
                    return func.Call(args);
                }
            }
            catch (Exception ex)
            {
                string msg = "[Lua] error: " + ex.ToString();
                Debug.Print(msg, 2, Debug.DebugColor.Red);
                InformationManager.DisplayMessage(new InformationMessage(msg, Colors.Red));
            }
            return new object[1];
        }
    }
}
